'''
Created on 09/02/2011

@author: Vinicius
'''

from cluster import KMeans
from csv import reader
from padrao import Padrao

k=3
input = reader(open('iris.data','r'))
entradas = []
for attributes in input:
    p = Padrao()
    label = attributes[len(attributes)-1]
    p.label = label
    for i in range(len(attributes)-1):
        p.atributos.append(float(attributes[i]))
    entradas.append(p)
        

def main():
    kMeans = KMeans(k,entradas)
    kMeans.executar()
    clusters = kMeans.clusters
    print ' ===== k - M E A N S =====\nIteracoes: '+str(kMeans.iteracoes)
    for i in range(len(kMeans.centroides)):
        print '\nCentro #'+str(i)+': '+str(kMeans.centroides[i].atributos)
    for i in range(len(clusters)):
        cluster = clusters[i]
        print '\nConteudo do cluster# '+str(i)+'. Padroes: '+str(len(cluster.padroes))+'\n'
        for padrao in cluster.padroes:
            print padrao.label
    
main()